﻿@using BonjourQuotation.UI.Models.PartialModel
@model QuotationCostPriceGridViewModel
<script type="text/javascript">
    var InvQuotaPriceModel;
   
    LoadInvQuotaPriceGrid();
    function LoadInvQuotaPriceGrid()
    {
        InvQuotaPriceModel = $(@Html.Raw(Json.Encode(Model))).JSModel();
        var InvQuotaPricecolumnHeaders = [];
        var InvQuotaPricecolumns = [];
        var InvQuotaPricecolWidth = [];
        if (InvQuotaPriceModel[0].Rows.length > 0) {
            OperationInvoiceQuotaPricesLastPaxValue = InvQuotaPriceModel[0].Rows[InvQuotaPriceModel[0].Rows.length - 1].PaxL
        }
        //InvQuotaPricecolumnHeaders.push("#");
        //InvQuotaPricecolumns.push({ data: "LineNo", type: "numeric", readOnly : true });
        //InvQuotaPricecolWidth.push(50);

        InvQuotaPricecolumnHeaders.push("Px");
        InvQuotaPricecolumns.push({ data: "PaxL", type: "numeric", readOnly: true });
        InvQuotaPricecolWidth.push(50);

        InvQuotaPricecolumnHeaders.push("Sold");
        InvQuotaPricecolumns.push({ data: "Sold", type: "numeric", format: '0,0.00', readOnly: true });
        InvQuotaPricecolWidth.push(70);

        InvQuotaPricecolumnHeaders.push("Given");
        InvQuotaPricecolumns.push({ data: "GivenFree", type: "numeric", format: '0,0.00', readOnly: true });
        InvQuotaPricecolWidth.push(80);

        InvQuotaPricecolumnHeaders.push("SOLD");
        InvQuotaPricecolumns.push({ data: "GivenSold", type: "numeric", format: '0,0.00', readOnly: true });
        InvQuotaPricecolWidth.push(80);

        InvQuotaPricecolumnHeaders.push("F. Adjs.");
        InvQuotaPricecolumns.push({ data: "FAdjust", type: "numeric", format: '0,0.00', readOnly: true });
        InvQuotaPricecolWidth.push(80);

        InvQuotaPricecolumnHeaders.push("F. Price");
        InvQuotaPricecolumns.push({ data: "FinalPrice", type: "numeric", format: '0,0.00', readOnly: true });
        InvQuotaPricecolWidth.push(80);

        InvQuotaPricecolumnHeaders.push("Curr");
        InvQuotaPricecolumns.push({ data: "CurrencyCostPrice", type: "text", readOnly: true });
        InvQuotaPricecolWidth.push(80);

        RedColorRenderer = function (instance, td, row, col, prop, value, cellProperties) {
            Handsontable.renderers.TextRenderer.apply(this, arguments);
            td.style.color = 'red';
        };
        BlackColorRenderer = function (instance, td, row, col, prop, value, cellProperties) {
            Handsontable.renderers.TextRenderer.apply(this, arguments);
            td.style.color = 'black';
        };

        InvQuotRedColorRendererForNegative = function (instance, td, row, col, prop, value, cellProperties) {
            Handsontable.renderers.NumericRenderer.apply(this, arguments);
            td.style.color = 'red';
        };

        var InvQuotaPriceData = InvQuotaPriceModel[0].Rows;
        $('#OperInvQuotaPriceGrid').show();
        $('#OperInvQuotaPriceGrid').handsontable({
            data: InvQuotaPriceData,
            minSpareRows: 0,
            colHeaders: InvQuotaPricecolumnHeaders,
            colWidths: InvQuotaPricecolWidth,
            contextMenu: false,
            manualColumnResize: true,
            columns: InvQuotaPricecolumns,
            cells: function (row, col, prop) {
                var Cellinstance = this;
                if (Cellinstance.renderer == Handsontable.renderers.NumericRenderer && Cellinstance.instance.getDataAtCell(row, col) < 0) {
                    Cellinstance.renderer = InvQuotRedColorRendererForNegative;
                }
                if (prop == "CurrencyCostPrice") {
                    var Curr = Cellinstance.instance.getData()[row].CurrencyCostPrice;
                    if (isCad(Curr)) {
                        Cellinstance.renderer = RedColorRenderer;
                    }
                    else {
                        Cellinstance.renderer = BlackColorRenderer;
                    }

                }
            }
        });
    }
    function isCad(curr) {
        if (curr != null) {
            if (curr == "CA") {
                return true; // 5 for friday, 6 for saturday
            }
            else
                return false;
        }
        else
            return false;
    }
    function GetLastPaxValue()
    {
        debugger
        var OperInvQuotaPriceGriddata = $('#OperInvQuotaPriceGrid').data('handsontable').getData();
        var Pax = $('#OperInvQuotaPriceGrid').data('handsontable').getData()[OperInvQuotaPriceGriddata.length - 1].PaxL;
        return Pax;
    };
</script>
<div id="OperInvQuotaPriceGridMain">
    <div style="width: 1185px; height:130px;">
        <div id="OperInvQuotaPriceGrid" class="handsontable" style="float:right; width: 545px; height: 110px; overflow: auto; display: none;">
        </div>
        <div style="float:left; width: 600px; height: 110px; padding-top:25px;">
            @if (@Model.HasProposal)
            {
                <div id="ProposalDiv">
                    <div>
                        @Html.TextBoxFor(model => model.Proposal, new { @style = "Display:None", @id = "ProposalFIleHidden" })
                        @Html.LabelForModel(Model.Proposal.Split('/').Last(), new { @class = "table_inputs_470" })
                        <input type="button" class="btn14 btn120" onclick="ViewInvoiceProposal()" value="View Proposal">
                    </div>
                    <div style="text-align:center; margin-bottom: 10px;">
                        <span style="color:red;">Please check the prices in the proposal before sending the invoice to customer!</span>
                    </div>
                </div>
            }
            <div class="pull-right">
                @*@Html.LabelFor(model => Model.SSSum, new { @class = "ColorBlue" })
                @Html.LabelForModel(Model.SSSum)*@
                @Html.LabelFor(model => Model.SSSumFinal, new { @class = "ColorBlue" })
                @Html.LabelForModel(Model.SSSumFinal)
                @if (Model.SSSumFinalCad != "")
                {
                    @Html.LabelForModel(Model.SSSumFinalCad, new { @style="color:Red"})
                }
                <input type="button" class="btn14 btn60" onclick="javascript: $('#OperInvQuotaPriceGridMain').hide()" value="Hide">
            </div>
            
        </div>
    </div>
    
</div>






